package com.openbravo.pos.panels;

import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import cn.ekuma.data.dao.I_DataLogic;
import cn.ekuma.data.ui.swing.dnd.AbstractJBeanDropPanel;
import cn.ekuma.epos.db.table.I_LocationLayoutCurrent;
import com.openbravo.bean.LocationLayout;
import com.openbravo.bean.LocationLayoutCurrent;
import com.openbravo.bean.ProductInfo;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.query.QBFParameter;
import com.openbravo.data.loader.query.QBFParameters;
import com.openbravo.pos.base.AppLocal;

public class JDropProductByLocationLayoutPanel  extends JPanel {
	I_DataLogic dlSales ;
	QBFParameters delQBFParameters;
	QBFParameter productParameter=new QBFParameter(I_LocationLayoutCurrent.PRODUCT);
	QBFParameter locationLayoutParameter=new QBFParameter(I_LocationLayoutCurrent.LOCATIONLAYOUT);
	/**
	 * Create the panel.
	 */
	public JDropProductByLocationLayoutPanel(final I_DataLogic dlSales2) {
		initComponents();
		this.dlSales=dlSales2;
		delQBFParameters=new QBFParameters();
		delQBFParameters.and(productParameter).and(locationLayoutParameter);
		
		add(new AbstractJBeanDropPanel<LocationLayout,ProductInfo>(){
			@Override
			public void doDropInsert(List<ProductInfo> beans) {
				LocationLayoutCurrent locationLayout;
						for(ProductInfo p:beans){	
						try {
							locationLayout=new LocationLayoutCurrent();
							locationLayout.setLocationLayoutId(bean.getKey());
							locationLayout.setProductId(p.getID());
							locationLayout.setUnits(1);
							dlSales.insert(locationLayout);
						} catch (BasicException e) {
							e.printStackTrace();
						}
						}
			}
			
			public void doDropDelete(List<ProductInfo> dropList) {
				locationLayoutParameter.equal(bean.getKey());
				for(ProductInfo p:dropList){			
					productParameter.equal(p.getID());
					try {
					   dlSales.deleteByQBFParameters(LocationLayoutCurrent.class, delQBFParameters);
					} catch (BasicException e) {
						e.printStackTrace();
					}
				  }
			} 

			@Override
			public String readerBean(LocationLayout obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("label.locationLayout");
			}
		});
		
		
		add(new AbstractJBeanDropPanel<LocationLayout,ProductInfo>(){
			@Override
			public void doDropInsert(List<ProductInfo> beans) {
				LocationLayoutCurrent locationLayout;
						for(ProductInfo p:beans){	
						try {
							locationLayout=new LocationLayoutCurrent();
							locationLayout.setLocationLayoutId(bean.getKey());
							locationLayout.setProductId(p.getID());
							locationLayout.setUnits(1);
							dlSales.insert(locationLayout);
						} catch (BasicException e) {
							e.printStackTrace();
						}
						}
			}
			
			public void doDropDelete(List<ProductInfo> dropList) {
				locationLayoutParameter.equal(bean.getKey());
				for(ProductInfo p:dropList){			
					productParameter.equal(p.getID());
					try {
					   dlSales.deleteByQBFParameters(LocationLayoutCurrent.class, delQBFParameters);
					} catch (BasicException e) {
						e.printStackTrace();
					}
				  }
			} 

			@Override
			public String readerBean(LocationLayout obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("label.locationLayout");
			}
		});
		add(new AbstractJBeanDropPanel<LocationLayout,ProductInfo>(){
			@Override
			public void doDropInsert(List<ProductInfo> beans) {
				LocationLayoutCurrent locationLayout;
						for(ProductInfo p:beans){	
						try {
							locationLayout=new LocationLayoutCurrent();
							locationLayout.setLocationLayoutId(bean.getKey());
							locationLayout.setProductId(p.getID());
							locationLayout.setUnits(1);
							dlSales.insert(locationLayout);
						} catch (BasicException e) {
							e.printStackTrace();
						}
						}
			}
			
			public void doDropDelete(List<ProductInfo> dropList) {
				locationLayoutParameter.equal(bean.getKey());
				for(ProductInfo p:dropList){			
					productParameter.equal(p.getID());
					try {
					   dlSales.deleteByQBFParameters(LocationLayoutCurrent.class, delQBFParameters);
					} catch (BasicException e) {
						e.printStackTrace();
					}
				  }
			} 

			@Override
			public String readerBean(LocationLayout obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("label.locationLayout");
			}
		});
		add(new AbstractJBeanDropPanel<LocationLayout,ProductInfo>(){
			@Override
			public void doDropInsert(List<ProductInfo> beans) {
				LocationLayoutCurrent locationLayout;
						for(ProductInfo p:beans){	
						try {
							locationLayout=new LocationLayoutCurrent();
							locationLayout.setLocationLayoutId(bean.getKey());
							locationLayout.setProductId(p.getID());
							locationLayout.setUnits(1);
							dlSales.insert(locationLayout);
						} catch (BasicException e) {
							e.printStackTrace();
						}
						}
			}
			
			public void doDropDelete(List<ProductInfo> dropList) {
				locationLayoutParameter.equal(bean.getKey());
				for(ProductInfo p:dropList){			
					productParameter.equal(p.getID());
					try {
					   dlSales.deleteByQBFParameters(LocationLayoutCurrent.class, delQBFParameters);
					} catch (BasicException e) {
						e.printStackTrace();
					}
				  }
			} 

			@Override
			public String readerBean(LocationLayout obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("label.locationLayout");
			}
		});
		add(new AbstractJBeanDropPanel<LocationLayout,ProductInfo>(){
			@Override
			public void doDropInsert(List<ProductInfo> beans) {
				LocationLayoutCurrent locationLayout;
						for(ProductInfo p:beans){	
						try {
							locationLayout=new LocationLayoutCurrent();
							locationLayout.setLocationLayoutId(bean.getKey());
							locationLayout.setProductId(p.getID());
							locationLayout.setUnits(1);
							dlSales.insert(locationLayout);
						} catch (BasicException e) {
							e.printStackTrace();
						}
						}
			}
			
			public void doDropDelete(List<ProductInfo> dropList) {
				locationLayoutParameter.equal(bean.getKey());
				for(ProductInfo p:dropList){			
					productParameter.equal(p.getID());
					try {
					   dlSales.deleteByQBFParameters(LocationLayoutCurrent.class, delQBFParameters);
					} catch (BasicException e) {
						e.printStackTrace();
					}
				  }
			} 

			@Override
			public String readerBean(LocationLayout obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("label.locationLayout");
			}
		});
		add(new AbstractJBeanDropPanel<LocationLayout,ProductInfo>(){
			@Override
			public void doDropInsert(List<ProductInfo> beans) {
				LocationLayoutCurrent locationLayout;
						for(ProductInfo p:beans){	
						try {
							locationLayout=new LocationLayoutCurrent();
							locationLayout.setLocationLayoutId(bean.getKey());
							locationLayout.setProductId(p.getID());
							locationLayout.setUnits(1);
							dlSales.insert(locationLayout);
						} catch (BasicException e) {
							e.printStackTrace();
						}
						}
			}
			
			public void doDropDelete(List<ProductInfo> dropList) {
				locationLayoutParameter.equal(bean.getKey());
				for(ProductInfo p:dropList){			
					productParameter.equal(p.getID());
					try {
					   dlSales.deleteByQBFParameters(LocationLayoutCurrent.class, delQBFParameters);
					} catch (BasicException e) {
						e.printStackTrace();
					}
				  }
			} 

			@Override
			public String readerBean(LocationLayout obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				return AppLocal.getIntString("label.locationLayout");
			}
		});
	}
	private void initComponents() {
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
	}
	
	public static String getTabName(){
		return AppLocal.getIntString("label.productCustomerView");
	}

}